﻿#region
/*******************************************************************************
** File Name:		    FoodDepartmentService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodDepartmentService : IFoodDepartmentService
    {
		 IFoodDepartment foodDepartment = new FoodDepartmentRepository();
		 
		 #region  Auto Generation
		 
        public void AddFoodDepartment(FoodDepartmentModel model)
        {
			EFoodDepartment entity = ConvertModelToEntity(model);
			
            foodDepartment.AddFoodDepartment(entity);
        }

		public void UpdateByFoodDepartmentID (FoodDepartmentModel model)
		{
			EFoodDepartment entity = ConvertModelToEntity(model);

            foodDepartment.UpdateByFoodDepartmentID(entity);

		}

		public void DeleteByFoodDepartmentID (System.Int64 foodDepartmentID)
		{
		
            foodDepartment.DeleteByFoodDepartmentID(foodDepartmentID);

		}
		 
        public FoodDepartmentModel GetByFoodDepartmentID (System.Int64 foodDepartmentID)
        {
        
			EFoodDepartment entity = foodDepartment.GetByFoodDepartmentID(foodDepartmentID);
			
            FoodDepartmentModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodDepartmentModel> GetAll ()
		{
			IList<EFoodDepartment> entity = foodDepartment.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodDepartmentModel> list = new List<FoodDepartmentModel>();

            foreach (var item in entity)
            {
                FoodDepartmentModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodDepartmentModel ConvertEntityToModel(EFoodDepartment entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodDepartmentModel model = new FoodDepartmentModel();
                        model.FoodDepartmentID = entity.FoodDepartmentID;
                        model.Name = entity.Name;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EFoodDepartment ConvertModelToEntity(FoodDepartmentModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodDepartment entity = new EFoodDepartment();
                        entity.FoodDepartmentID = model.FoodDepartmentID;
                        entity.Name = model.Name;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}